package com.glacier.yuyuan.gen.webapp.domain;

import cn.hutool.core.util.StrUtil;
import cn.hutool.db.meta.Column;
import com.glacier.common.core.domain.BaseEntity;

import java.util.Map;

/**
 * date 2023-01-29 09:01
 * 代码生成表字段
 *
 * @author glacier
 * @version 1.0.0
 */
public class GenTableField extends BaseEntity {

    private static final long serialVersionUID = 7924296596720541898L;
    /**
     * 表ID
     */
    private String tableId;

    /**
     * 字段名称
     */
    private String fieldName;

    /**
     * 字段类型
     */
    private String fieldType;

    /**
     * 字段说明
     */
    private String fieldComment;

    /**
     * 属性名
     */
    private String attrName;

    /**
     * 属性类型
     */
    private String attrType;

    /**
     * 类型名称
     */
    private String attrTypeName;

    /**
     * 排序
     */
    private Integer sort;

    /**
     * 主键 1：是，2：否
     */
    private String primaryPk;

    /**
     * 基类字段 1：是，2：否
     */
    private String baseField;

    /**
     * 表单项 1：是，2：否
     */
    private String formItem;

    /**
     * 表单必填 1：是，2：否
     */
    private String formRequired;

    /**
     * 表单类型
     */
    private String formType;

    /**
     * 表单字典类型
     */
    private String formDict;

    /**
     * 表单效验
     */
    private String formValidator;

    /**
     * 列表项 1：是，2：否
     */
    private String gridItem;

    /**
     * 列表排序 1：是，2：否
     */
    private String gridSort;

    /**
     * 查询项 1：是，2：否
     */
    private String queryItem;

    /**
     * 查询方式
     */
    private String queryType;

    /**
     * 查询表单类型
     */
    private String queryFormType;

    /**
     * 查询字典类型
     */
    private String queryDict;

    public GenTableField() {
    }

    public GenTableField(String id) {
        super(id);
    }

    public String getTableId() {
        return tableId;
    }

    public void setTableId(String tableId) {
        this.tableId = tableId;
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getFieldType() {
        return fieldType;
    }

    public void setFieldType(String fieldType) {
        this.fieldType = fieldType;
    }

    public String getFieldComment() {
        return fieldComment;
    }

    public void setFieldComment(String fieldComment) {
        this.fieldComment = fieldComment;
    }

    public String getAttrName() {
        return attrName;
    }

    public void setAttrName(String attrName) {
        this.attrName = attrName;
    }

    public String getAttrType() {
        return attrType;
    }

    public void setAttrType(String attrType) {
        this.attrType = attrType;
    }

    public String getAttrTypeName() {
        return attrTypeName;
    }

    public void setAttrTypeName(String attrTypeName) {
        this.attrTypeName = attrTypeName;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public String getPrimaryPk() {
        return primaryPk;
    }

    public void setPrimaryPk(String primaryPk) {
        this.primaryPk = primaryPk;
    }

    public String getBaseField() {
        return baseField;
    }

    public void setBaseField(String baseField) {
        this.baseField = baseField;
    }

    public String getFormItem() {
        return formItem;
    }

    public void setFormItem(String formItem) {
        this.formItem = formItem;
    }

    public String getFormRequired() {
        return formRequired;
    }

    public void setFormRequired(String formRequired) {
        this.formRequired = formRequired;
    }

    public String getFormType() {
        return formType;
    }

    public void setFormType(String formType) {
        this.formType = formType;
    }

    public String getFormDict() {
        return formDict;
    }

    public void setFormDict(String formDict) {
        this.formDict = formDict;
    }

    public String getFormValidator() {
        return formValidator;
    }

    public void setFormValidator(String formValidator) {
        this.formValidator = formValidator;
    }

    public String getGridItem() {
        return gridItem;
    }

    public void setGridItem(String gridItem) {
        this.gridItem = gridItem;
    }

    public String getGridSort() {
        return gridSort;
    }

    public void setGridSort(String gridSort) {
        this.gridSort = gridSort;
    }

    public String getQueryItem() {
        return queryItem;
    }

    public void setQueryItem(String queryItem) {
        this.queryItem = queryItem;
    }

    public String getQueryType() {
        return queryType;
    }

    public void setQueryType(String queryType) {
        this.queryType = queryType;
    }

    public String getQueryFormType() {
        return queryFormType;
    }

    public void setQueryFormType(String queryFormType) {
        this.queryFormType = queryFormType;
    }

    public String getQueryDict() {
        return queryDict;
    }

    public void setQueryDict(String queryDict) {
        this.queryDict = queryDict;
    }

    public GenTableField autoFill(Column column, Map<String, GenFieldType> fieldTypeMap) {
        // todo: implement
        this.fieldName = column.getName();
        this.attrName = StrUtil.toCamelCase(column.getName());
        this.fieldComment = column.getComment();
        this.fieldType = column.getTypeName();
        GenFieldType genFieldType = fieldTypeMap.get(column.getTypeName());
        this.attrType = genFieldType.getAttrType();
        this.attrTypeName = genFieldType.getAttrTypeName();
        this.primaryPk = column.isPk() ? "1" : "2";
        return this;
    }

    @Override
    public String toString() {
        return "GenTableField{" +
                "tableId=" + tableId +
                ", fieldName='" + fieldName + '\'' +
                ", fieldType='" + fieldType + '\'' +
                ", fieldComment='" + fieldComment + '\'' +
                ", attrName='" + attrName + '\'' +
                ", attrType='" + attrType + '\'' +
                ", attrTypeName='" + attrTypeName + '\'' +
                ", sort=" + sort +
                ", primaryPk=" + primaryPk +
                ", baseField=" + baseField +
                ", formItem=" + formItem +
                ", formRequired=" + formRequired +
                ", formType='" + formType + '\'' +
                ", formDict='" + formDict + '\'' +
                ", formValidator='" + formValidator + '\'' +
                ", gridItem=" + gridItem +
                ", gridSort=" + gridSort +
                ", queryItem=" + queryItem +
                ", queryType='" + queryType + '\'' +
                ", queryFormType='" + queryFormType + '\'' +
                ", queryDict='" + queryDict + '\'' +
                ", id='" + id + '\'' +
                ", createBy='" + createBy + '\'' +
                ", createTime=" + createTime +
                ", updateBy='" + updateBy + '\'' +
                ", updateTime=" + updateTime +
                ", remark='" + remark + '\'' +
                '}';
    }
}
